import matplotlib.pyplot as plt
import dolphindb as ddb

s = ddb.session("192.168.200.179", 8832, "chenzhimin", "suhhgjy98y_JHg87")


result = s.run("""

stk_price = select * from loadTable("dfs://ods_stock_quotation","ods_stock_quotation") where  end_date >= 2014.01.01 and if_trading_day = 1
""")

data = {
    'Value1': [-0.02,	0.06,	-0.07,	0.07,	0.03,	0.08,	0.1,	0,	0.01,	-0.06,	-0.01,	0.02,	-0.1,	0.05,	0.04,	0.09,	-0.04,	-0.03,	-0.08,	-0.05,	-0.09,	0.13,	0.15,	0.35	],
    'Value2': [1032, 1312, 83, 1004, 2615, 598, 5836, 1852, 2348, 133, 1289, 2744, 140, 1705, 2258, 371, 440, 777, 42, 224, 53, 1, 1, 1]
}

# 按照 'Value1' 的值进行排序
sorted_indices = sorted(range(len(data['Value1'])), key=lambda i: data['Value1'][i])
sorted_value1 = [data['Value1'][i] for i in sorted_indices]
sorted_value2 = [data['Value2'][i] for i in sorted_indices]

# 设置柱状图的宽度
bar_width = 0.5

# 绘制柱状图
plt.bar(range(len(sorted_value1)), sorted_value2, width=bar_width)

# 设置横坐标刻度和标签，并旋转45度
plt.xticks(range(len(sorted_value1)), sorted_value1, rotation=45)

# 添加标题和标签
plt.title('Bar Chart of Value2 with respect to Value1')
plt.xlabel('Value1')
plt.ylabel('Value2')

plt.show()
